package practise.mulitThreads.ConcurrentInPractice.PageRender;

import java.util.List;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;

/**
 * Created by richard on 6/13/14.
 */
public class PageRender {
    ExecutorService fixPool ;
    public void renderPage(CharSequence source){
        List<String> resources = getDownloadResource(source);
        Page page = new Page();
        CompletionService<String> completionService = new ExecutorCompletionService<>(fixPool);

        for(String str : resources){
            completionService.submit(new PageContentDownload(str));
        }

        renderPageText(source , page);

        for(int i =0 ; i < resources.size();i++){
            try {
                renderPageImage(completionService.poll().get(),page);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }

    private List<String> getDownloadResource(CharSequence source){
       return null;
    }
    private void renderPageText(CharSequence source, Page page){

    }
    private void renderPageImage(String source, Page page){

    }
}
